function mem(mode)
% mem - do a whos and add up the byte sizes
if(nargin == 0)
   mode = 0;
end;

s = whos; % get the current variables in memory (that's just this routine).
n = 0;
m = 0;
for i = 1: length(s)
   n = n + s(i).bytes;
end;
m = m + length(s);

s = evalin('caller', 'whos'); % get memory usage in the routine that called us
   for i = 1: length(s)
      n = n + s(i).bytes;
   end;
   m = m + length(s);

switch mode
   
case 1 % include the base workspace
s = evalin('base', 'whos'); % get memory usage in the routine that called us
   for i = 1: length(s)
      n = n + s(i).bytes;
   end;
   m = m + length(s);
otherwise
end;

fprintf(1, 'Memory Usage: %d bytes in %d objects\n', n, m);
return;
